package com.pda.gongpin.ui.fullinventory;

import android.os.Bundle;

import androidx.recyclerview.widget.RecyclerView;

import com.pda.gongpin.R;
import com.pda.gongpin.adapter.UnshelveAdapter;
import com.pda.gongpin.bean.UnshelveBean;
import com.pda.gongpin.contract.UnshelveContract;
import com.pda.gongpin.presenter.UnshelvePresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class FullInventoryFragment extends BaseMvpFragment<UnshelvePresenter> implements UnshelveContract.View, OnRefreshListener {
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    UnshelveAdapter unshelveAdapter;
    String taskNo;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;

    public FullInventoryFragment(String taskNo) {
        this.taskNo = taskNo;
    }

    public FullInventoryFragment() {
    }

    @Override
    public UnshelvePresenter getPresenter() {
        return new UnshelvePresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        unshelveAdapter = new UnshelveAdapter(R.layout.item_unshelve, new ArrayList<>());
        rvContent.setAdapter(unshelveAdapter);
       smart.autoRefresh();
    }

    @Override
    public void initLinsenterner() {
        unshelveAdapter.setOnChildCallClick(new UnshelveAdapter.OnChildCallClick() {
            @Override
            public void onCallUp(UnshelveBean.WholePalletDetailVoListBean callUpDialog) {
                Bundle bundle = new Bundle();
                bundle.putString("taskResultId", callUpDialog.getTaskResultId());
                startIntent(AppActivityKey.FULLINVENTORYDETAILSACTIVITY, bundle);
            }
        });

    }

    @Override
    public void getData() {

    }

    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.autoRefresh();
    }

    @Override
    public void setList(List<UnshelveBean> list) {
        unshelveAdapter.setNewInstance(list);
        smart.finishRefresh();
    }

    @Override
    public void onSuccess() {

    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.wholePalletDetailList(taskNo);
    }
}
